package com.ldj.hibernate;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;

import com.ldj.struts.form.MyFileInfoForm;

public class MyFileInfoDAO extends BaseHibernateDAO {
	public MyFileInfoDAO(HttpServletRequest request, HttpServletResponse response) {
		super(request, response);
		// TODO Auto-generated constructor stub
	}

	private static final Log log = LogFactory.getLog(MyFileInfoDAO.class);
	
	public List findAllPage(MyFileInfoForm mfForm) {
		try {
			String queryString = "from MyFileInfo where myFileInfoDelOper='0' ";
			if(mfForm.getMyFileInfoFileTitle() != null && !"".equals(mfForm.getMyFileInfoFileTitle())){
				queryString += " and myFileInfoFileTitle like '%" + mfForm.getMyFileInfoFileTitle() + "%'";
			}
			if(mfForm.getMyFileInfoCreateTime() != null && !"".equals(mfForm.getMyFileInfoCreateTime())){
				queryString += " and myFileInfoCreateTime = '" + mfForm.getMyFileInfoCreateTime()+ "'";
			}
			queryString += "order by myFileInfoCreateTime desc";
			Query queryObject = getSession().createQuery(queryString);
			this.setPageSize(8);
			return this.jlist(queryObject);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
	public MyFileInfo findById(java.lang.String id) {
		log.debug("getting MyFileInfo instance with id: " + id);
		try {
			MyFileInfo instance = (MyFileInfo) getSession().get(
					"com.ldj.hibernate.MyFileInfo", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	public void save(MyFileInfo transientInstance) {
		log.debug("saving MyFileInfo instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
	
	public MyFileInfo merge(MyFileInfo detachedInstance) {
		try {
			MyFileInfo result = (MyFileInfo) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}
	
	public void delete(NewsInfo persistentInstance) {
		log.debug("deleting NewsInfo instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}
}